package com.zsrt.oa.order.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zsrt.oa.order.service.OrderService;
import com.zsrt.oa.order.service.impl.OrderServiceImpl;
import com.zsrt.utils.DBUtils;

/**
 * 订单的控制层
 * @author 罗智壕-13424431416
 *
 * 2017年6月11日
 */
public class OrderController extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	/**
	 * 初始化订单的服务层
	 */
	private OrderService service = new OrderServiceImpl();
    
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		String method = request.getParameter("method");
		if(null != method && !"".equals(method.trim())){
			Map<String, Object> map = new HashMap<String,Object>();
			HttpSession session = request.getSession();
			Object userId = session.getAttribute("currentUser");
			if("preOrderAdd".equals(method)){
				String ticketId = request.getParameter("ticketId");
				String price = request.getParameter("money");
				//调用订单的增加
				service.orderAdd(price, userId, ticketId, map);
			}else if("myMessage".equals(method)){
				
				//查询当前用户的所有订单
				service.myOrderMessage((String) userId, map);
			}
			
			DBUtils.toJson(map, response);
		}
	}
}
